package pattern.create.builder;

import pattern.create.builder.builder.GoblinBuilder;
import pattern.create.builder.builder.HumanBuilder;
import pattern.create.builder.builder.OgreBuilder;
import pattern.create.builder.builder.PersonBuilder;
import pattern.create.builder.director.DoubleHeadPersonDirector;
import pattern.create.builder.director.NormalPersonDirector;
import pattern.create.builder.director.PersonDirector;
import pattern.create.builder.director.ThreeArmPersonDirector;
import pattern.create.builder.product.Person;

/**
 * BUILDER(生成器)模式
 * 在以下情况使用Builder模式
 * - 当创建复杂对象的算法应该独立于该对象的组成部分以及它们的装配方式时。
 * - 当构造过程必须允许被构造的对象有不同的表示时。
 * @author xuyuji
 *
 */
public class Client {

	/**
	 * 创建普通人类
	 */
	public void createNormalHuman(){
		PersonDirector director = new NormalPersonDirector();
		PersonBuilder builder = new HumanBuilder();
		Person normalHuman = director.createPerson(builder);
		normalHuman.showInfo();
	}
	
	/**
	 * 创造食人魔法师
	 */
	public void createOgreMage(){
		PersonDirector director = new DoubleHeadPersonDirector();
		PersonBuilder builder = new OgreBuilder();
		Person ogreMage = director.createPerson(builder);
		ogreMage.showInfo();
	}
	
	/**
	 * 创造变异哥布林
	 */
	public void createMutantGoblin(){
		PersonDirector director = new ThreeArmPersonDirector();
		PersonBuilder builder = new GoblinBuilder();
		Person mutantGoblin = director.createPerson(builder);
		mutantGoblin.showInfo();
	}
}
